package com.atguigu.order.vo;

import com.atguigu.common.vo.MemberAddressVo;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * description: OrderConfirmVo
 * date: 2022/12/22 18:01
 * author: MR.孙
 */
@Data
public class OrderConfirmVo {
    /**
     * 所有用户收货人地址信息
     */
    List<MemberAddressVo> memberAddressVos;

    /**
     * 商品项
     */
    List<OrderItemVo> items;

    /**
     * 积分
     */
    private Integer integration;

    /**
     * 商品总价
     */
    private BigDecimal total;

    /**
     * 应支付价格
     */
    private BigDecimal payPrice;

    /**
     * 防重令牌，防止订单多次提交
     */
    private String orderToken;

    private Map<Long, Boolean> hasStock;

    public Integer getCount(){
        Integer i =0;
        if (items!=null && items.size()>0) {
            for (OrderItemVo item : items) {
                i = i + item.getCount();
            }
        }
        return i;
    }


    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null && items.size()>0) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum =sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
